// Retrofit Api Interface implement class,auto generation
package com.demo;

import com.okhttp.retrofit.BaseResponseBodyHandler;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.ResponseBody;
import retrofit2.Call;

/**
 *
 * @author GYL
 * @dateTime 20200507 22:46
 * @description  Net3:接口封装实现类
 * @see Net3
 *
 */
public class Net3Service {
  private static Net3 _innerCall;

  /**
   * 生成接口唯一码（WHAT）
   */
  private static final AtomicInteger sNextGeneratedId = new AtomicInteger(10);

  /**
   * 创建Api服务
   */
  private static Net3 innerCall() {
    if(_innerCall==null){
      _innerCall=com.okhttp.retrofit.RetrofitClient.getInstance().createService(Net3.class);
    }
    return _innerCall;
  }

  /**
   * 生成接口唯一码(What)
   */
  private static int generateWhat() {
    for (;;) {
      final int result = sNextGeneratedId.get();
       // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
        int newValue = result + 1;
        if (newValue > 0x00FFFFFF) {
        // Roll over to 1, not 0.
        newValue = 1;
    }
      if (sNextGeneratedId.compareAndSet(result, newValue)) {
      return result;  
    }
    }}

  /**
   *
   * {@link com.demo.Net3#doGet2} 
   * @param test 
   * @param handler  BaseResponseBodyHandler<T> 
   *
   */
  public static <T> int doGet2(String test, BaseResponseBodyHandler<T> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<ResponseBody> call = innerCall().doGet2(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net3#doGet3} 
   * @param test 
   * @param handler  ResultBodyHandler<DataBean> 
   *
   */
  public static int doGet3(String test, ResultBodyHandler<DataBean> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<ResponseBody> call = innerCall().doGet3(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net3#doGet4} 
   * @param test 
   * @param handler  ResultHandler2<DataBean> 
   *
   */
  public static int doGet4(String test, ResultHandler2<DataBean> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<Result<DataBean>> call = innerCall().doGet4(test); 
    call.enqueue(handler); 
    return  what;
  }
}
